package com.darren.euc.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonFormat;

@Entity
@Table(name = "euc_spaces")
public class Space implements Serializable {

	private static final long serialVersionUID = 2861478466077717714L;

	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	@Column(name = "space_name")
	private String spaceName;	
	
	@OneToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name = "province_id",referencedColumnName="province_id")
	private Province province;	

	@OneToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name = "city_id",referencedColumnName="city_id")
	private City city;
	
	@Column(name = "address")
	private String address;

	@Column(name = "postal_code")
	private String postalCode;
	
	@OneToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name = "status_id",referencedColumnName="status_id")
	private SpaceStatus spaceStatus;

	@Column(name = "space_area")
	private Integer spaceArea;	
	
	@Column(name = "seat_count")
	private Integer seatCount;
	
	@Column(name = "seat_used_count")
	private Integer seatUsedCount;
	
	@Column(name = "meeting_room_count")
	private Integer meetingroomCount;	

	@Column(name = "contact_number")
	private String contactNumber;
	
	@Column(name = "introduction")
	private String introduction;
	
	
	@Column(name = "display_picture")
	private String displayPicture;
	
	@Column(name = "display_picture2")
	private String displayPicture2;
	
	@Column(name = "display_picture3")
	private String displayPicture3;
	
	@Column(name = "other_facilities")
	private String otherFacilities;
	
	@ManyToOne(targetEntity = User.class, fetch = FetchType.EAGER)
	@JoinColumn(name = "user_id", referencedColumnName = "user_id") 
	private User createUser;
	
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
	@Column(name = "create_time")
	private Date createTime;
	
	
	//@OneToMany(mappedBy = "meetingroom")
	//@JoinColumn(name = "space_id")	
	@OneToMany(mappedBy="space",cascade={CascadeType.ALL})
	private List<Meetingroom> meetingroomList = new ArrayList<>();

	//@OneToMany(mappedBy = "room")
	//@JoinColumn(name = "space_id")
	@OneToMany(mappedBy="space",cascade={CascadeType.ALL})
	private List<Room> roomList = new ArrayList<>();
	

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getSpaceName() {
		return spaceName;
	}

	public void setSpaceName(String spaceName) {
		this.spaceName = spaceName;
	}

	public Province getProvince() {
		if(province != null && province.getCities() != null){
			//province.getCities().clear();
		}		
		return province;
	}

	public void setProvince(Province province) {
		this.province = province;
	}

	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public SpaceStatus getSpaceStatus() {
		return spaceStatus;
	}

	public void setSpaceStatus(SpaceStatus spaceStatus) {
		this.spaceStatus = spaceStatus;
	}

	public Integer getSpaceArea() {
		return spaceArea == null?0:spaceArea;
	}

	public void setSpaceArea(Integer spaceArea) {
		this.spaceArea = spaceArea;
	}

	public Integer getSeatCount() {
//		if(roomList != null && roomList.size() > 0){
//			seatCount = 0;
//			for(Room room:roomList){
//				if(room.isEnable() == true){
//					seatCount += room.getSeatCount();
//				}				
//			}
//		}
		return seatCount == null?0:seatCount;
	}

	public void setSeatCount(Integer seatCount) {
		this.seatCount = seatCount == null?0:seatCount;
	}

	public Integer getSeatUsedCount() {
		return seatUsedCount == null?0:seatUsedCount;
	}

	public void setSeatUsedCount(Integer seatUsedCount) {
		this.seatUsedCount = seatUsedCount == null?0:seatUsedCount;
	}

	public Integer getMeetingroomCount() {
		if(meetingroomList != null && meetingroomList.size() > 0){
			meetingroomCount = 0;
			for(Meetingroom meetingroom:meetingroomList){
				if(meetingroom.isEnable() == true){
					meetingroomCount++;
				}
			}
		}
		return meetingroomCount == null?0:meetingroomCount;
	}

	public void setMeetingroomCount(Integer meetingroomCount) {
		this.meetingroomCount = meetingroomCount == null?0:meetingroomCount;
	}

	public String getContactNumber() {
		return contactNumber;
	}

	public void setContactNumber(String contactNumber) {
		this.contactNumber = contactNumber;
	}

	public String getIntroduction() {
		return introduction;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public String getDisplayPicture() {
		return displayPicture;
	}

	public void setDisplayPicture(String displayPicture) {
		this.displayPicture = displayPicture;
	}
	
	

	public String getDisplayPicture2() {
		return displayPicture2;
	}

	public void setDisplayPicture2(String displayPicture2) {
		this.displayPicture2 = displayPicture2;
	}

	public String getDisplayPicture3() {
		return displayPicture3;
	}

	public void setDisplayPicture3(String displayPicture3) {
		this.displayPicture3 = displayPicture3;
	}

	public String getOtherFacilities() {
		return otherFacilities;
	}

	public void setOtherFacilities(String otherFacilities) {
		this.otherFacilities = otherFacilities;
	}

	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public List<Meetingroom> getMeetingroomList() {
		return new ArrayList<Meetingroom>();//meetingroomList;
	}

	public void setMeetingroomList(List<Meetingroom> meetingroomList) {
		this.meetingroomList = meetingroomList;
	}

	public List<Room> getRoomList() {
		return new ArrayList<Room>();//roomList;
	}

	public void setRoomList(List<Room> roomList) {
		this.roomList = roomList;
	}
	
}
